$(document).ready(function(){		
	$("#addUser").val(username);
	
	var src = tl_config.last_url;	
	var i = src.indexOf('?');
	var j =src.indexOf('&');
	if(i!=-1){		
		var id = src.substring(i+4,j);		
		var parentTitle=src.substring(j+7);			
		$("#parentId").val(id);
		$("p#parentTitle").text(parentTitle);		
	}	
	
	//表单验证
	var validate = $("#fromChildHelpCenterAdd").validate({		   
			rules:{					
				title:{
					  required:true,
				      remote: { 
		                   url: server_url+'/rest/HelpCenterInfo/checkTitle.do?timestamp='+Math.random()+ '&token=' + token,
		                   type: "post",
		                   dataType: "json", 
		                   data: {	
		                	        parentId: function() { return $("#parentId").val();},
		                	        title: function() { return $("#title").val();}
		                         } 
		               },
		               stringMaxLength:30
				}
			},
			messages:{				
				title:{
				           required:"该值不能为空！",
	                       remote:"标题名已存在，请重新输入!",
	                       stringMaxLength:"最多能输入30个字符！"
	                   }
			},
			submitHandler:function(){
				sub();
			},
			errorPlacement: function(error, element) {
				if ( element.is(":radio") )
					error.appendTo ( element.parent() );
				else if ( element.is(":checkbox") )
					error.appendTo ( element.parent() );
				else if ( element.is("input[name=captcha]") )
					error.appendTo ( element.parent() );
				else
					error.insertAfter(element);
			},
			validClass : 'rightValidate',
		    success: function(label) {
			   label.html("&nbsp;").text(" ") ;
		    }
	 });	
	
});


//提交
function sub(){	
	if($("#fromChildHelpCenterAdd").valid()){
		$.ajax({			
			url:server_url+'rest/HelpCenterInfo/HelpCenterInfoAdd.do?ran='+Math.random()+ '&token=' + token,
			type:'post',
			data:$("#fromChildHelpCenterAdd").serialize(),
			success:function(data){
				easyDialog.open({container:{header:'温馨提示',content:data.retMsg},autoClose : 2000});
				back();
			}
		});
	}
}


function back(){
    var url="getHelpCenterChildListPage.do?ran="+Math.random();
	tl_config.loadToWorkArea(url);
}
//文本框字数动态显示

function submitCommit(){
	$("#fromChildHelpCenterAdd").submit();
}
